﻿using System;
using Omnia.Infrastructure;
using Omnia.Enums;
using System.Data.Linq.Mapping;

namespace Omnia.DataModels
{
    [Table(Name = "Transactions")]
    public partial class TransactionInfo : NotificationObject
    {
        public TransactionInfo() { }

        #region Fields
        private string guid = System.Guid.NewGuid().ToString();
        private string caseGuid;
        private TransactionKindValue kind = TransactionKindValue.Expense;
        private DateTime time = DateTime.Now;
        private double amount = 0;
        private string categoryGuid;
        private PaymentWayValue paymentway = PaymentWayValue.Cash;
        private string remark = string.Empty;
        private string place;
        #endregion

        #region Properties
        [Column(IsPrimaryKey = true)]
        public string Guid
        {
            get { return guid; }
            set
            {
                guid = value;
                RaisePropertyChanged(() => Guid);
            }
        }

        [Column]
        public string CaseGuid
        {
            get { return caseGuid; }
            set
            {
                caseGuid = value;
                RaisePropertyChanged(() => CaseGuid);
            }
        }

        [Column]
        public TransactionKindValue Kind
        {
            get { return kind; }
            set
            {
                kind = value;
                RaisePropertyChanged(() => Kind);
            }
        }

        [Column]
        public DateTime Time
        {
            get { return time; }
            set
            {
                time = value;
                RaisePropertyChanged(() => Time);
            }
        }

        [Column]
        public double Amount
        {
            get { return amount; }
            set
            {
                amount = value;
                RaisePropertyChanged(() => Amount);
            }
        }

        [Column]
        public string CategoryGuid
        {
            get { return categoryGuid; }
            set
            {
                categoryGuid = value;
                RaisePropertyChanged(() => CategoryGuid);
            }
        }

        [Column]
        public PaymentWayValue Paymentway
        {
            get { return paymentway; }
            set
            {
                paymentway = value;
                RaisePropertyChanged(() => Paymentway);
            }
        }

        [Column]
        public string Remark
        {
            get { return remark; }
            set
            {
                remark = value;
                RaisePropertyChanged(() => Remark);
            }
        }

        [Column]
        public string Place
        {
            get { return place; }
            set
            {
                place = value;
                RaisePropertyChanged(() => Place);
            }
        }

        public int Day
        {
            get
            {
                return Time.Day;
            }
        }

        public int Month
        {
            get
            {
                return Time.Month;
            }
        }

        public int Year
        {
            get { return Time.Year; }
        }

        public CategoryInfo Category
        {
            get;
            set;
        }

        public CaseInfo Case { get; set; }

        public bool EditEnable
        {
            get
            {
                TimeSpan tsStart = TimeSpan.FromTicks(DateTime.Now.Ticks);
                TimeSpan tsEnd = TimeSpan.FromTicks(Time.Ticks);

                TimeSpan ts = tsStart.Subtract(tsEnd).Duration();

                return ts.TotalHours < 24;
            }
        }
        #endregion
    }
}
